<?php
namespace Admin\Controller;

use Think\Controller;

class WeigisController extends Controller
{
    public function index()
    {
        $this->display();
    }

    public function gis()
    {
        $this->display();
    }
    public function tree()
    {
        $checktime = I('checktime');
        $weiuser = M('weiuser');
        $weiuser_list = $weiuser->where('subscribe=1')->select();
        foreach ($weiuser_list as $key => $value) {
            $sumpoint = $this->getSumPointByOpenid($value['openid'], $checktime);
            $weiuser_list[$key]['nickname'] = $weiuser_list[$key]['nickname'] . "-(" . $sumpoint . ")";
            $weiuser_list[$key]['checktime'] = $checktime;
        }
        //dump($weiuser_list);
        if (!empty($weiuser_list)) {
            echo json_encode($weiuser_list);
        } else {
            echo null;
        }

    }
    public function location()
    {
        $res = array();
        $checktime = I('checktime');
        $openid = I('openid');
        $location = M('weiuserlocation');
        $con['weiuser_openid'] = $openid;
        $con['addtime'] = array('like', $checktime . '%');
        $location_list = $location->where($con)->select();
        foreach ($location_list as $key => $value) {
            $location_list[$key]['checktime'] = $value['addtime'];
            $location_list[$key]['y'] = $value['lat'];
            $location_list[$key]['x'] = $value['lng'];
        }
        if (!empty($location_list)) {
            $res['status'] = 1;
            $res['data'] = $location_list;
            $res['info'] = "成功";
        } else {
            $res['status'] = 0;
            $res['data'] = null;
            $res['info'] = "失败";
        }
        echo json_encode($res);

    }
    public function getSumPointByOpenid($openid, $time)
    {
        $location = M('weiuserlocation');
        $con['weiuser_openid'] = $openid;
        $con['addtime'] = array('like', $time . '%');
        $location_sum = $location->where($con)->count();
        return $location_sum;
    }

}
